from django.conf import settings
import logging

import pytz
from pytz import timezone, gae

def utc_from_localtime(datetime):
    if datetime.tzinfo is None:
        from_tz = pytz.timezone(settings.TIME_ZONE)
        datetime = datetime.replace(tzinfo=from_tz).astimezone(pytz.utc)
    else:
        datetime = datetime.astimezone(pytz.utc)
    return datetime

def localtime_from_utc(datetime):
    from_tz = pytz.timezone(settings.TIME_ZONE)
    if datetime.tzinfo is None:
        datetime = datetime.replace(tzinfo=pytz.utc).astimezone(from_tz)
    else:
        datetime = datetime.astimezone(from_tz)
    return datetime

